home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / phpMyAdmin / libraries / display_tbl.lib.php < prev    next >
PHP Script  |  2005-03-12  |  100KB  |  1,910 lines

  1. <?php
  2. /* $Id: display_tbl.lib.php,v 2.74 2005/03/13 13:23:08 lem9 Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5. /**
  6.  * Set of functions used to display the records returned by a sql query
  7.  */
  8.  
  9. /**
  10.  * Defines the display mode to use for the results of a sql query
  11.  *
  12.  * It uses a synthetic string that contains all the required informations.
  13.  * In this string:
  14.  *   - the first two characters stand for the action to do while
  15.  *     clicking on the "edit" link (eg 'ur' for update a row, 'nn' for no
  16.  *     edit link...);
  17.  *   - the next two characters stand for the action to do while
  18.  *     clicking on the "delete" link (eg 'kp' for kill a process, 'nn' for
  19.  *     no delete link...);
  20.  *   - the next characters are boolean values (1/0) and respectively stand
  21.  *     for sorting links, navigation bar, "insert a new row" link, the
  22.  *     bookmark feature, the expand/collapse text/blob fields button and
  23.  *     the "display printable view" option.
  24.  *     Of course '0'/'1' means the feature won't/will be enabled.
  25.  *
  26.  * @param   string   the synthetic value for display_mode (see º1 a few
  27.  *                   lines above for explanations)
  28.  * @param   integer  the total number of rows returned by the sql query
  29.  *                   without any programmatically appended "LIMIT" clause
  30.  *                   (just a copy of $unlim_num_rows if it exists, else
  31.  *                   computed inside this function)
  32.  *
  33.  * @return  array    an array with explicit indexes for all the display
  34.  *                   elements
  35.  *
  36.  * @global  string   the database name
  37.  * @global  string   the table name
  38.  * @global  integer  the total number of rows returned by the sql query
  39.  *                   without any programmatically appended "LIMIT" clause
  40.  * @global  array    the properties of the fields returned by the query
  41.  * @global  string   the url to return to in case of error in a sql
  42.  *                   statement
  43.  *
  44.  * @access  private
  45.  *
  46.  * @see     PMA_displayTable()
  47.  */
  48. function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
  49. {
  50.     global $db, $table;
  51.     global $unlim_num_rows, $fields_meta;
  52.     global $err_url;
  53.  
  54.     // 1. Initializes the $do_display array
  55.     $do_display              = array();
  56.     $do_display['edit_lnk']  = $the_disp_mode[0] . $the_disp_mode[1];
  57.     $do_display['del_lnk']   = $the_disp_mode[2] . $the_disp_mode[3];
  58.     $do_display['sort_lnk']  = (string) $the_disp_mode[4];
  59.     $do_display['nav_bar']   = (string) $the_disp_mode[5];
  60.     $do_display['ins_row']   = (string) $the_disp_mode[6];
  61.     $do_display['bkm_form']  = (string) $the_disp_mode[7];
  62.     $do_display['text_btn']  = (string) $the_disp_mode[8];
  63.     $do_display['pview_lnk'] = (string) $the_disp_mode[9];
  64.  
  65.     // 2. Display mode is not "false for all elements" -> updates the
  66.     // display mode
  67.     if ($the_disp_mode != 'nnnn000000') {
  68.         // 2.0 Print view -> set all elements to FALSE!
  69.         if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
  70.             $do_display['edit_lnk']  = 'nn'; // no edit link
  71.             $do_display['del_lnk']   = 'nn'; // no delete link
  72.             $do_display['sort_lnk']  = (string) '0';
  73.             $do_display['nav_bar']   = (string) '0';
  74.             $do_display['ins_row']   = (string) '0';
  75.             $do_display['bkm_form']  = (string) '0';
  76.             $do_display['text_btn']  = (string) '0';
  77.             $do_display['pview_lnk'] = (string) '0';
  78.         }
  79.         // 2.1 Statement is a "SELECT COUNT", a
  80.         //     "CHECK/ANALYZE/REPAIR/OPTIMIZE", an "EXPLAIN" one or
  81.         //     contains a "PROC ANALYSE" part
  82.         else if ($GLOBALS['is_count'] || $GLOBALS['is_analyse'] || $GLOBALS['is_maint'] || $GLOBALS['is_explain']) {
  83.             $do_display['edit_lnk']  = 'nn'; // no edit link
  84.             $do_display['del_lnk']   = 'nn'; // no delete link
  85.             $do_display['sort_lnk']  = (string) '0';
  86.             $do_display['nav_bar']   = (string) '0';
  87.             $do_display['ins_row']   = (string) '0';
  88.             $do_display['bkm_form']  = (string) '1';
  89.             if ($GLOBALS['is_analyse']) {
  90.                 $do_display['text_btn']  = (string) '1';
  91.             } else {
  92.                 $do_display['text_btn']  = (string) '0';
  93.             }
  94.             $do_display['pview_lnk'] = (string) '1';
  95.         }
  96.         // 2.2 Statement is a "SHOW..."
  97.         else if ($GLOBALS['is_show']) {
  98.             // 2.2.1 TODO : defines edit/delete links depending on show statement
  99.             $tmp = preg_match('@^SHOW[[:space:]]+(VARIABLES|(FULL[[:space:]]+)?PROCESSLIST|STATUS|TABLE|GRANTS|CREATE|LOGS|DATABASES|FIELDS)@i', $GLOBALS['sql_query'], $which);
  100.             if (isset($which[1]) && strpos(' ' . strtoupper($which[1]), 'PROCESSLIST') > 0) {
  101.                 $do_display['edit_lnk'] = 'nn'; // no edit link
  102.                 $do_display['del_lnk']  = 'kp'; // "kill process" type edit link
  103.             }
  104.             else {
  105.                 // Default case -> no links
  106.                 $do_display['edit_lnk'] = 'nn'; // no edit link
  107.                 $do_display['del_lnk']  = 'nn'; // no delete link
  108.             }
  109.             // 2.2.2 Other settings
  110.             $do_display['sort_lnk']  = (string) '0';
  111.             $do_display['nav_bar']   = (string) '0';
  112.             $do_display['ins_row']   = (string) '0';
  113.             $do_display['bkm_form']  = (string) '1';
  114.             $do_display['text_btn']  = (string) '1';
  115.             $do_display['pview_lnk'] = (string) '1';
  116.         }
  117.         // 2.3 Other statements (ie "SELECT" ones) -> updates
  118.         //     $do_display['edit_lnk'], $do_display['del_lnk'] and
  119.         //     $do_display['text_btn'] (keeps other default values)
  120.         else {
  121.             $prev_table = $fields_meta[0]->table;
  122.             $do_display['text_btn']  = (string) '1';
  123.             for ($i = 0; $i < $GLOBALS['fields_cnt']; $i++) {
  124.                 $is_link = ($do_display['edit_lnk'] != 'nn'
  125.                             || $do_display['del_lnk'] != 'nn'
  126.                             || $do_display['sort_lnk'] != '0'
  127.                             || $do_display['ins_row'] != '0');
  128.                 // 2.3.2 Displays edit/delete/sort/insert links?
  129.                 if ($is_link
  130.                     && ($fields_meta[$i]->table == '' || $fields_meta[$i]->table != $prev_table)) {
  131.                     $do_display['edit_lnk'] = 'nn'; // don't display links
  132.                     $do_display['del_lnk']  = 'nn';
  133.                     // TODO: May be problematic with same fields names in
  134.                     //       two joined table.
  135.                     // $do_display['sort_lnk'] = (string) '0';
  136.                     $do_display['ins_row']  = (string) '0';
  137.                     if ($do_display['text_btn'] == '1') {
  138.                         break;
  139.                     }
  140.                 } // end if (2.3.2)
  141.                 // 2.3.3 Always display print view link
  142.                 $do_display['pview_lnk']    = (string) '1';
  143.                 $prev_table = $fields_meta[$i]->table;
  144.             } // end for
  145.         } // end if..elseif...else (2.1 -> 2.3)
  146.     } // end if (2)
  147.  
  148.     // 3. Gets the total number of rows if it is unknown
  149.     if (isset($unlim_num_rows) && $unlim_num_rows != '') {
  150.         $the_total = $unlim_num_rows;
  151.     }
  152.     else if (($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1')
  153.              && (!empty($db) && !empty($table))) {
  154.         $the_total   = PMA_countRecords($db, $table, TRUE);
  155.     }
  156.  
  157.     // 4. If navigation bar or sorting fields names urls should be
  158.     //    displayed but there is only one row, change these settings to
  159.     //    false
  160.     if ($do_display['nav_bar'] == '1' || $do_display['sort_lnk'] == '1') {
  161.  
  162.         if (isset($unlim_num_rows) && $unlim_num_rows < 2) {
  163.             // garvin: force display of navbar for vertical/horizontal display-choice.
  164.             // $do_display['nav_bar']  = (string) '0';
  165.             $do_display['sort_lnk'] = (string) '0';
  166.         }
  167.  
  168.     } // end if (3)
  169.  
  170.     // 5. Updates the synthetic var
  171.     $the_disp_mode = join('', $do_display);
  172.  
  173.     return $do_display;
  174. } // end of the 'PMA_setDisplayMode()' function
  175.  
  176.  
  177. /**
  178.  * Displays a navigation bar to browse among the results of a sql query
  179.  *
  180.  * @param   integer  the offset for the "next" page
  181.  * @param   integer  the offset for the "previous" page
  182.  * @param   string   the url-encoded query
  183.  *
  184.  * @global  string   the current language
  185.  * @global  string   the currect charset for MySQL
  186.  * @global  integer  the server to use (refers to the number in the
  187.  *                   configuration file)
  188.  * @global  string   the database name
  189.  * @global  string   the table name
  190.  * @global  string   the url to go back in case of errors
  191.  * @global  integer  the total number of rows returned by the sql query
  192.  * @global  integer  the total number of rows returned by the sql query
  193.  *                   without any programmatically appended "LIMIT" clause
  194.  * @global  integer  the current position in results
  195.  * @global  mixed    the maximum number of rows per page ('all' = no limit)
  196.  * @global  string   the display mode (horizontal/vertical/horizontalflipped)
  197.  * @global  integer  the number of row to display between two table headers
  198.  * @global  boolean  whether to limit the number of displayed characters of
  199.  *                   text type fields or not
  200.  *
  201.  * @access  private
  202.  *
  203.  * @see     PMA_displayTable()
  204.  */
  205. function PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_query)
  206. {
  207.     global $lang, $convcharset, $server, $db, $table;
  208.     global $goto;
  209.     global $num_rows, $unlim_num_rows, $pos, $session_max_rows;
  210.     global $disp_direction, $repeat_cells;
  211.     global $dontlimitchars;
  212.     global $is_innodb;
  213.     global $showtable;
  214.  
  215.     // FIXME: move this to a central place
  216.     // FIXME: for other future table types
  217.     $is_innodb = (isset($showtable['Type']) && $showtable['Type'] == 'InnoDB');
  218.  
  219.     ?>
  220.  
  221. <!-- Navigation bar -->
  222. <table border="0" cellpadding="2" cellspacing="0">
  223. <tr>
  224.     <?php
  225.     // Move to the beginning or to the previous page
  226.     if ($pos > 0 && $session_max_rows != 'all') {
  227.         // loic1: patch #474210 from Gosha Sakovich - part 1
  228.         if ($GLOBALS['cfg']['NavigationBarIconic']) {
  229.             $caption1 = '<<';
  230.             $caption2 = ' < ';
  231.             $title1   = ' title="' . $GLOBALS['strPos1'] . '"';
  232.             $title2   = ' title="' . $GLOBALS['strPrevious'] . '"';
  233.         } else {
  234.             $caption1 = $GLOBALS['strPos1'] . ' <<';
  235.             $caption2 = $GLOBALS['strPrevious'] . ' <';
  236.             $title1   = '';
  237.             $title2   = '';
  238.         } // end if... else...
  239.         ?>
  240. <td>
  241.     <form action="sql.php" method="post">
  242.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  243.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  244.         <input type="hidden" name="pos" value="0" />
  245.         <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
  246.         <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
  247.         <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
  248.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  249.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  250.         <input type="submit" name="navig" value="<?php echo $caption1; ?>"<?php echo $title1; ?> />
  251.     </form>
  252. </td>
  253. <td>
  254.     <form action="sql.php" method="post">
  255.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  256.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  257.         <input type="hidden" name="pos" value="<?php echo $pos_prev; ?>" />
  258.         <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
  259.         <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
  260.         <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
  261.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  262.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  263.         <input type="submit" name="navig" value="<?php echo $caption2; ?>"<?php echo $title2; ?> />
  264.     </form>
  265. </td>
  266.         <?php
  267.     } // end move back
  268.     echo "\n";
  269.     ?>
  270. <td>
  271.        
  272. </td>
  273. <td align="center">
  274.     <form action="sql.php" method="post"
  275.         onsubmit="return (checkFormElementInRange(this, 'session_max_rows', 1) && checkFormElementInRange(this, 'pos', 0, <?php echo $unlim_num_rows - 1; ?>))">
  276.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  277.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  278.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  279.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  280.         <input type="submit" name="navig" value="<?php echo $GLOBALS['strShow']; ?> :" />
  281.         <input type="text" name="session_max_rows" size="3" value="<?php echo (($session_max_rows != 'all') ? $session_max_rows : $GLOBALS['cfg']['MaxRows']); ?>" class="textfield" onfocus="this.select()" />
  282.         <?php echo $GLOBALS['strRowsFrom'] . "\n"; ?>
  283.         <input type="text" name="pos" size="6" value="<?php echo (($pos_next >= $unlim_num_rows) ? 0 : $pos_next); ?>" class="textfield" onfocus="this.select()" />
  284.         <br />
  285.     <?php
  286.     // Display mode (horizontal/vertical and repeat headers)
  287.     $param1 = '            <select name="disp_direction">' . "\n"
  288.             . '                <option value="horizontal"' . (($disp_direction == 'horizontal') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeHorizontal'] . '</option>' . "\n"
  289.             . '                <option value="horizontalflipped"' . (($disp_direction == 'horizontalflipped') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeFlippedHorizontal'] . '</option>' . "\n"
  290.             . '                <option value="vertical"' . (($disp_direction == 'vertical') ? ' selected="selected"': '') . '>' . $GLOBALS['strRowsModeVertical'] . '</option>' . "\n"
  291.             . '            </select>' . "\n"
  292.             . '           ';
  293.     $param2 = '            <input type="text" size="3" name="repeat_cells" value="' . $repeat_cells . '" class="textfield" />' . "\n"
  294.             . '           ';
  295.     echo '    ' . sprintf($GLOBALS['strRowsModeOptions'], "\n" . $param1, "\n" . $param2) . "\n";
  296.     ?>
  297.     </form>
  298. </td>
  299. <td>
  300.        
  301. </td>
  302.     <?php
  303.     // Move to the next page or to the last one
  304.     if (($pos + $session_max_rows < $unlim_num_rows) && $num_rows >= $session_max_rows
  305.         && $session_max_rows != 'all') {
  306.         // loic1: patch #474210 from Gosha Sakovich - part 2
  307.         if ($GLOBALS['cfg']['NavigationBarIconic']) {
  308.             $caption3 = ' > ';
  309.             $caption4 = '>>';
  310.             $title3   = ' title="' . $GLOBALS['strNext'] . '"';
  311.             $title4   = ' title="' . $GLOBALS['strEnd'] . '"';
  312.         } else {
  313.             $caption3 = '> ' . $GLOBALS['strNext'];
  314.             $caption4 = '>> ' . $GLOBALS['strEnd'];
  315.             $title3   = '';
  316.             $title4   = '';
  317.         } // end if... else...
  318.         echo "\n";
  319.         ?>
  320. <td>
  321.     <form action="sql.php" method="post">
  322.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  323.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  324.         <input type="hidden" name="pos" value="<?php echo $pos_next; ?>" />
  325.         <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
  326.         <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
  327.         <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
  328.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  329.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  330.         <input type="submit" name="navig" value="<?php echo $caption3; ?>"<?php echo $title3; ?> />
  331.     </form>
  332. </td>
  333. <td>
  334.     <form action="sql.php" method="post"
  335.         onsubmit="return <?php echo (($pos + $session_max_rows < $unlim_num_rows && $num_rows >= $session_max_rows) ? 'true' : 'false'); ?>">
  336.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  337.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  338.         <input type="hidden" name="pos" value="<?php echo @((ceil($unlim_num_rows / $session_max_rows)- 1) * $session_max_rows); ?>" />
  339.         <?php
  340.         if ($is_innodb && $unlim_num_rows > $GLOBALS['cfg']['MaxExactCount']) {
  341.             echo '<input type="hidden" name="find_real_end" value="1" />' . "\n";
  342.             // no backquote around this message
  343.             $onclick = ' onclick="return confirmAction(\'' . PMA_jsFormat($GLOBALS['strLongOperation'], FALSE) . '\')"';
  344.         }
  345.         ?>
  346.         <input type="hidden" name="session_max_rows" value="<?php echo $session_max_rows; ?>" />
  347.         <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
  348.         <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
  349.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  350.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  351.         <input type="submit" name="navig" value="<?php echo $caption4; ?>"<?php echo $title4; ?> <?php echo (empty($onclick) ? '' : $onclick); ?>/>
  352.     </form>
  353. </td>
  354.         <?php
  355.     } // end move toward
  356.  
  357.  
  358.     //page redirection
  359.     $pageNow = @floor($pos / $session_max_rows) + 1;
  360.     $nbTotalPage = @ceil($unlim_num_rows / $session_max_rows);
  361.  
  362.     if ($nbTotalPage > 1){ //if1
  363.        ?>
  364.    <td>
  365.           
  366.    </td>
  367.    <td>
  368.         <?php //<form> for keep the form alignment of button < and << ?>
  369.         <form>
  370.         <?php echo PMA_pageselector(
  371.                      'sql.php?sql_query='        . $encoded_query .
  372.                         '&session_max_rows=' . $session_max_rows .
  373.                         '&disp_direction='   . $disp_direction .
  374.                         '&repeat_cells='     . $repeat_cells .
  375.                         '&goto='             . $goto .
  376.                         '&dontlimitchars='   . $dontlimitchars .
  377.                         '&'                  . PMA_generate_common_url($db, $table) .
  378.                         '&',
  379.                      $session_max_rows,
  380.                      $pageNow,
  381.                      $nbTotalPage
  382.               );
  383.         ?>
  384.         </form>
  385.     </td>
  386.         <?php
  387.     } //_if1
  388.  
  389.  
  390.     // Show all the records if allowed
  391.     if ($GLOBALS['cfg']['ShowAll'] && ($num_rows < $unlim_num_rows)) {
  392.         echo "\n";
  393.         ?>
  394. <td>
  395.        
  396. </td>
  397. <td>
  398.     <form action="sql.php" method="post">
  399.         <?php echo PMA_generate_common_hidden_inputs($db, $table); ?>
  400.         <input type="hidden" name="sql_query" value="<?php echo $encoded_query; ?>" />
  401.         <input type="hidden" name="pos" value="0" />
  402.         <input type="hidden" name="session_max_rows" value="all" />
  403.         <input type="hidden" name="disp_direction" value="<?php echo $disp_direction; ?>" />
  404.         <input type="hidden" name="repeat_cells" value="<?php echo $repeat_cells; ?>" />
  405.         <input type="hidden" name="goto" value="<?php echo $goto; ?>" />
  406.         <input type="hidden" name="dontlimitchars" value="<?php echo $dontlimitchars; ?>" />
  407.         <input type="submit" name="navig" value="<?php echo $GLOBALS['strShowAll']; ?>" />
  408.     </form>
  409. </td>
  410.         <?php
  411.     } // end show all
  412.     echo "\n";
  413.     ?>
  414. </tr>
  415. </table>
  416.  
  417.     <?php
  418. } // end of the 'PMA_displayTableNavigation()' function
  419.  
  420.  
  421. /**
  422.  * Displays the headers of the results table
  423.  *
  424.  * @param   array    which elements to display
  425.  * @param   array    the list of fields properties
  426.  * @param   integer  the total number of fields returned by the sql query
  427.  * @param   array    the analyzed query
  428.  *
  429.  * @return  boolean  always true
  430.  *
  431.  * @global  string   the current language
  432.  * @global  string   the current charset for MySQL
  433.  * @global  integer  the server to use (refers to the number in the
  434.  *                   configuration file)
  435.  * @global  string   the database name
  436.  * @global  string   the table name
  437.  * @global  string   the sql query
  438.  * @global  string   the url to go back in case of errors
  439.  * @global  integer  the total number of rows returned by the sql query
  440.  * @global  integer  the current position in results
  441.  * @global  integer  the maximum number of rows per page
  442.  * @global  array    informations used with vertical display mode
  443.  * @global  string   the display mode (horizontal/vertical/horizontalflipped)
  444.  * @global  integer  the number of row to display between two table headers
  445.  * @global  boolean  whether to limit the number of displayed characters of
  446.  *                   text type fields or not
  447.  *
  448.  * @access  private
  449.  *
  450.  * @see     PMA_displayTable()
  451.  */
  452. function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $analyzed_sql = '')
  453. {
  454.     global $lang, $convcharset, $server, $db, $table;
  455.     global $goto, $text_url;
  456.     global $sql_query, $num_rows, $pos, $session_max_rows;
  457.     global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
  458.     global $dontlimitchars;
  459.  
  460.     if ($analyzed_sql == '') {
  461.         $analyzed_sql = array();
  462.     }
  463.  
  464.     // can the result be sorted?
  465.     if ($is_display['sort_lnk'] == '1') {
  466.  
  467.         // Just as fallback
  468.         $unsorted_sql_query     = $sql_query;
  469.         if (isset($analyzed_sql[0]['unsorted_query'])) {
  470.             $unsorted_sql_query = $analyzed_sql[0]['unsorted_query'];
  471.         }
  472.  
  473.         // we need $sort_expression and $sort_expression_nodir
  474.         // even if there are many table references
  475.  
  476.         $sort_expression = trim(str_replace('  ', ' ',$analyzed_sql[0]['order_by_clause']));
  477.  
  478.         // Get rid of ASC|DESC (TODO: analyzer)
  479.         preg_match('@(.*)([[:space:]]*(ASC|DESC))@si',$sort_expression,$matches);
  480.         $sort_expression_nodir = isset($matches[1]) ? trim($matches[1]) : $sort_expression;
  481.  
  482.         // sorting by indexes, only if it makes sense (only one table ref)
  483.         if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
  484.             isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
  485.             isset($analyzed_sql[0]['table_ref']) && count($analyzed_sql[0]['table_ref']) == 1) {
  486.  
  487.             // grab indexes data:
  488.             PMA_DBI_select_db($db);
  489.             if (!defined('PMA_IDX_INCLUDED')) {
  490.                 $ret_keys = PMA_get_indexes($table);
  491.             }
  492.  
  493.             $prev_index = '';
  494.             foreach ($ret_keys as $row) {
  495.  
  496.                 if ($row['Key_name'] != $prev_index ){
  497.                     $indexes[]  = $row['Key_name'];
  498.                     $prev_index = $row['Key_name'];
  499.                 }
  500.                 $indexes_info[$row['Key_name']]['Sequences'][]     = $row['Seq_in_index'];
  501.                 $indexes_info[$row['Key_name']]['Non_unique']      = $row['Non_unique'];
  502.                 if (isset($row['Cardinality'])) {
  503.                     $indexes_info[$row['Key_name']]['Cardinality'] = $row['Cardinality'];
  504.                 }
  505.             //    I don't know what does the following column mean....
  506.             //    $indexes_info[$row['Key_name']]['Packed']          = $row['Packed'];
  507.                 $indexes_info[$row['Key_name']]['Comment']         = (isset($row['Comment']))
  508.                                                                    ? $row['Comment']
  509.                                                                    : '';
  510.                 $indexes_info[$row['Key_name']]['Index_type']      = (isset($row['Index_type']))
  511.                                                                    ? $row['Index_type']
  512.                                                                    : '';
  513.  
  514.                 $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Column_name']  = $row['Column_name'];
  515.                 if (isset($row['Sub_part'])) {
  516.                     $indexes_data[$row['Key_name']][$row['Seq_in_index']]['Sub_part'] = $row['Sub_part'];
  517.                 }
  518.             } // end while
  519.  
  520.             // do we have any index?
  521.             if (isset($indexes_data)) {
  522.  
  523.                 if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  524.                     $span = $fields_cnt;
  525.                     if ($is_display['edit_lnk'] != 'nn') $span++;
  526.                     if ($is_display['del_lnk'] != 'nn') $span++;
  527.                     if ($is_display['del_lnk'] != 'kp' && $is_display['del_lnk'] != 'nn') $span++;
  528.                 } else {
  529.                     $span = $num_rows + floor($num_rows/$repeat_cells) + 1;
  530.                 }
  531.  
  532.                 echo '<form action="sql.php" method="post">' . "\n";
  533.                 echo PMA_generate_common_hidden_inputs($db, $table, 5);
  534.                 echo '<input type="hidden" name="pos" value="' . $pos .  '" />' . "\n";
  535.                 echo '<input type="hidden" name="session_max_rows" value="' . $session_max_rows . '" />' . "\n";
  536.                 echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
  537.                 echo '<input type="hidden" name="repeat_cells" value="' . $repeat_cells . '" />' . "\n";
  538.                 echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
  539.                 echo $GLOBALS['strSortByKey'] . ': <select name="sql_query">' . "\n";
  540.                 $used_index = false;
  541.                 $local_order = (isset($sort_expression) ? $sort_expression : '');
  542.                 foreach ($indexes_data AS $key => $val) {
  543.                     $asc_sort = '';
  544.                     $desc_sort = '';
  545.                     foreach ($val AS $key2 => $val2) {
  546.                         $asc_sort .= PMA_backquote($val2['Column_name']) . ' ASC , ';
  547.                         $desc_sort .= PMA_backquote($val2['Column_name']) . ' DESC , ';
  548.                     }
  549.                     $asc_sort = substr($asc_sort, 0, -3);
  550.                     $desc_sort = substr($desc_sort, 0, -3);
  551.                     $used_index = $used_index || $local_order == $asc_sort || $local_order == $desc_sort;
  552.                     echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $asc_sort) . '"' . ($local_order == $asc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strAscending'] . ')</option>';
  553.                     echo "\n";
  554.                     echo '<option value="' . htmlspecialchars($unsorted_sql_query . ' ORDER BY ' . $desc_sort) . '"' . ($local_order == $desc_sort ? ' selected="selected"' : '') . '>' . htmlspecialchars($key) . ' (' . $GLOBALS['strDescending'] . ')</option>';
  555.                     echo "\n";
  556.                 }
  557.                 echo '<option value="' . htmlspecialchars($unsorted_sql_query) . '"' . ($used_index ? '' : ' selected="selected"' ) . '>' . $GLOBALS['strNone'] . '</option>';
  558.                 echo "\n";
  559.                 echo '</select> ';
  560.                 echo "\n";
  561.                 echo '<input type="submit" value="' . $GLOBALS['strGo'] . '" />';
  562.                 echo "\n";
  563.                 echo '</form>';
  564.                 echo "\n";
  565.             }
  566.         }
  567.     }
  568.  
  569.  
  570.     $vertical_display['emptypre']   = 0;
  571.     $vertical_display['emptyafter'] = 0;
  572.     $vertical_display['textbtn']    = '';
  573.  
  574.  
  575.     // Start of form for multi-rows delete
  576.  
  577.     if ($is_display['del_lnk'] == 'dr' || $is_display['del_lnk'] == 'kp' ) {
  578.         echo '<form method="post" action="tbl_row_action.php" name="rowsDeleteForm">' . "\n";
  579.         echo PMA_generate_common_hidden_inputs($db, $table, 1);
  580.         echo '<input type="hidden" name="disp_direction" value="' . $disp_direction . '" />' . "\n";
  581.         echo '<input type="hidden" name="repeat_cells"   value="' . $repeat_cells   . '" />' . "\n";
  582.         echo '<input type="hidden" name="goto"           value="sql.php" />' . "\n";
  583.         echo '<input type="hidden" name="dontlimitchars" value="' . $dontlimitchars . '" />' . "\n";
  584.     }
  585.  
  586.     echo '<!-- Results table -->' . "\n"
  587.        . '<table id="table_results" ';
  588.     if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
  589.         echo 'border="1" cellpadding="2" cellspacing="0"';
  590.     } else {
  591.         echo 'border="' . $GLOBALS['cfg']['Border'] . '" cellpadding="2" cellspacing="1"';
  592.     }
  593.     echo '>' . "\n";
  594.     if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  595.         ?>
  596. <!-- Results table headers -->
  597. <tr>
  598.         <?php
  599.         echo "\n";
  600.     }
  601.  
  602.     // 1. Displays the full/partial text button (part 1)...
  603.     if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  604.         $colspan  = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
  605.                   ? ' colspan="3"'
  606.                   : '';
  607.     } else {
  608.         $rowspan  = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn')
  609.                   ? ' rowspan="3"'
  610.                   : '';
  611.     }
  612.     $text_url = 'sql.php?'
  613.               . PMA_generate_common_url($db, $table)
  614.               . '&sql_query=' . urlencode($sql_query)
  615.               . '&pos=' . $pos
  616.               . '&session_max_rows=' . $session_max_rows
  617.               . '&pos=' . $pos
  618.               . '&disp_direction=' . $disp_direction
  619.               . '&repeat_cells=' . $repeat_cells
  620.               . '&goto=' . $goto
  621.               . '&dontlimitchars=' . (($dontlimitchars) ? 0 : 1);
  622.  
  623.     //     ... before the result table
  624.     if (($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
  625.         && $is_display['text_btn'] == '1') {
  626.         $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
  627.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  628.             ?>
  629. <th class="td" colspan="<?php echo $fields_cnt; ?>" align="center">
  630.     <a href="<?php echo $text_url; ?>">
  631.         <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_'.(($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png'; ?>" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
  632. </th>
  633. </tr>
  634.  
  635. <tr>
  636.             <?php
  637.         } // end horizontal/horizontalflipped mode
  638.         else {
  639.             echo "\n";
  640.             ?>
  641. <tr>
  642. <th class="td" colspan="<?php echo $num_rows + floor($num_rows/$repeat_cells) + 1; ?>" align="center">
  643.     <a href="<?php echo $text_url; ?>">
  644.         <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png'; ?>" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
  645. </th>
  646. </tr>
  647.             <?php
  648.         } // end vertical mode
  649.     }
  650.  
  651.     //     ... at the left column of the result table header if possible
  652.     //     and required
  653.     else if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && $is_display['text_btn'] == '1') {
  654.         $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
  655.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  656.             echo "\n";
  657.             ?>
  658. <th class="td" <?php echo $colspan; ?> align="center">
  659.     <a href="<?php echo $text_url; ?>">
  660.         <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png'; ?>" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
  661. </th>
  662.             <?php
  663.         } // end horizontal/horizontalflipped mode
  664.         else {
  665.             $vertical_display['textbtn'] = '    <th class="td" ' . $rowspan . ' align="center" valign="middle">' . "\n"
  666.                                          . '        <a href="' . $text_url . '">' . "\n"
  667.                                          . '            <img src="' . $GLOBALS['pmaThemeImage'] . 's_' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png" border="0" width="50" height="20" alt="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" /></a>' . "\n"
  668.                                          . '    </th>' . "\n";
  669.         } // end vertical mode
  670.     }
  671.  
  672.     //     ... else if no button, displays empty(ies) col(s) if required
  673.     else if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
  674.              && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')) {
  675.         $vertical_display['emptypre'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 0;
  676.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  677.             echo "\n";
  678.             ?>
  679. <td<?php echo $colspan; ?>></td>
  680.             <?php
  681.             echo "\n";
  682.         } // end horizontal/horizontalfipped mode
  683.         else {
  684.             $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
  685.         } // end vertical mode
  686.     }
  687.  
  688.     // 2. Displays the fields' name
  689.     // 2.0 If sorting links should be used, checks if the query is a "JOIN"
  690.     //     statement (see 2.1.3)
  691.  
  692.     // 2.0.1 Prepare Display column comments if enabled ($cfg['ShowBrowseComments']).
  693.     //       Do not show comments, if using horizontalflipped mode, because of space usage
  694.     if ($GLOBALS['cfg']['ShowBrowseComments'] && $GLOBALS['cfgRelation']['commwork'] && $disp_direction != 'horizontalflipped') {
  695.         $comments_map = array();
  696.         foreach ($analyzed_sql[0]['table_ref'] as $tbl) {
  697.  
  698.             $tb = $tbl['table_true_name'];
  699.  
  700.             $comments_map[$tb] = PMA_getComments($db, $tb);
  701.         }
  702.     }
  703.  
  704.     if ($GLOBALS['cfgRelation']['commwork'] && $GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
  705.         require_once('./libraries/transformations.lib.php');
  706.         $GLOBALS['mime_map'] = PMA_getMIME($db, $table);
  707.     }
  708.  
  709.     if ($is_display['sort_lnk'] == '1') {
  710.         //$is_join = preg_match('@(.*)[[:space:]]+FROM[[:space:]]+.*[[:space:]]+JOIN@im', $sql_query, $select_stt);
  711.         $is_join = (isset($analyzed_sql[0]['queryflags']['join']) ?TRUE:FALSE);
  712.         $select_expr = $analyzed_sql[0]['select_expr_clause'];
  713.     } else {
  714.         $is_join = FALSE;
  715.     }
  716.  
  717.     // garvin: See if we have to highlight any header fields of a WHERE query.
  718.     //  Uses SQL-Parser results.
  719.     $highlight_columns = array();
  720.     if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
  721.         isset($analyzed_sql[0]['where_clause_identifiers'])) {
  722.  
  723.         $wi = 0;
  724.         if (isset($analyzed_sql[0]['where_clause_identifiers']) && is_array($analyzed_sql[0]['where_clause_identifiers'])) {
  725.             foreach ($analyzed_sql[0]['where_clause_identifiers'] AS $wci_nr => $wci) {
  726.                 $highlight_columns[$wci] = 'true';
  727.             }
  728.         }
  729.     }
  730.  
  731.     for ($i = 0; $i < $fields_cnt; $i++) {
  732.         // garvin: See if this column should get highlight because it's used in the
  733.         //  where-query.
  734.         if (isset($highlight_columns[$fields_meta[$i]->name]) || isset($highlight_columns[PMA_backquote($fields_meta[$i]->name)])) {
  735.             $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
  736.         } else {
  737.             $column_style = '';
  738.         }
  739.  
  740.         // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled.
  741.         if (isset($comments_map) &&
  742.                 isset($comments_map[$fields_meta[$i]->table]) &&
  743.                 isset($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name])) {
  744.             /*$comments_table_wrap_pre = '<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><th>';
  745.             $comments_table_wrap_post = '</th></tr><tr><th style="font-size: 8pt; font-weight: normal">' . htmlspecialchars($comments_map[$fields_meta[$i]->name]) . '</td></tr></table>';*/
  746.             $comments_table_wrap_pre = '';
  747.             $comments_table_wrap_post = '<span class="tblcomment">' . htmlspecialchars($comments_map[$fields_meta[$i]->table][$fields_meta[$i]->name]) . '</span>';
  748.         } else {
  749.             $comments_table_wrap_pre = '';
  750.             $comments_table_wrap_post = '';
  751.         }
  752.  
  753.         // 2.1 Results can be sorted
  754.         if ($is_display['sort_lnk'] == '1') {
  755.  
  756.             // 2.1.1 Checks if the table name is required; it's the case
  757.             //       for a query with a "JOIN" statement and if the column
  758.             //       isn't aliased, or in queries like
  759.             //       SELECT `1`.`master_field` , `2`.`master_field`
  760.             //       FROM `PMA_relation` AS `1` , `PMA_relation` AS `2`
  761.  
  762.             if (($is_join
  763.                 //&& !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name . '~i', $select_stt[1], $parts))
  764.                 && !preg_match('~([^[:space:],]|`[^`]`)[[:space:]]+(as[[:space:]]+)?' . $fields_meta[$i]->name . '~i', $select_expr, $parts))
  765.                || ( isset($analyzed_sql[0]['select_expr'][$i]['expr'])
  766.                    && isset($analyzed_sql[0]['select_expr'][$i]['column'])
  767.                    && $analyzed_sql[0]['select_expr'][$i]['expr'] !=
  768.                    $analyzed_sql[0]['select_expr'][$i]['column']
  769.                   && !empty($fields_meta[$i]->table)) ) {
  770.                 //$sort_tbl = PMA_backquote($fields_meta[$i]->table) . '.';
  771.                 $sort_tbl = PMA_backquote($fields_meta[$i]->table) . ' . ';
  772.             } else {
  773.                 $sort_tbl = '';
  774.             }
  775.             // 2.1.2 Checks if the current column is used to sort the
  776.             //       results
  777.             if (empty($sort_expression)) {
  778.                 $is_in_sort = FALSE;
  779.             } else {
  780.                 // field name may be preceded by a space, or any number
  781.                 // of characters followed by a dot (tablename.fieldname)
  782.                 // so do a direct comparison
  783.                 // for the sort expression (avoids problems with queries
  784.                 // like "SELECT id, count(id)..." and clicking to sort
  785.                 // on id or on count(id) )
  786.                 $is_in_sort = ($sort_tbl . PMA_backquote($fields_meta[$i]->name) == $sort_expression_nodir ? TRUE : FALSE);
  787.             }
  788.             // 2.1.3 Check the field name for backquotes.
  789.             //       If it contains some, it's probably a function column
  790.             //       like 'COUNT(`field`)'
  791.             if (strpos(' ' . $fields_meta[$i]->name, '`') > 0) {
  792.                 $sort_order = ' ORDER BY \'' . $fields_meta[$i]->name . '\' ';
  793.             } else {
  794.                 $sort_order = ' ORDER BY ' . $sort_tbl . PMA_backquote($fields_meta[$i]->name) . ' ';
  795.             }
  796.             // 2.1.4 Do define the sorting url
  797.             if (!$is_in_sort) {
  798.                 // loic1: patch #455484 ("Smart" order)
  799.                 $cfg['Order']  = strtoupper($GLOBALS['cfg']['Order']);
  800.                 if ($cfg['Order'] == 'SMART') {
  801.                     $cfg['Order'] = (preg_match('@time|date@i', $fields_meta[$i]->type)) ? 'DESC' : 'ASC';
  802.                 }
  803.                 $sort_order .= $cfg['Order'];
  804.                 $order_img   = '';
  805.             }
  806.             else if (preg_match('@[[:space:]]ASC$@i', $sort_expression)) {
  807.                 $sort_order .= ' DESC';
  808.                 $order_img   = ' <img src="' . $GLOBALS['pmaThemeImage'] . 's_asc.png" border="0" width="11" height="9" alt="'. $GLOBALS['strAscending'] . '" title="'. $GLOBALS['strAscending'] . '" id="soimg' . $i . '" />';
  809.             }
  810.             else if (preg_match('@[[:space:]]DESC$@i', $sort_expression)) {
  811.                 $sort_order .= ' ASC';
  812.                 $order_img   = ' <img src="' . $GLOBALS['pmaThemeImage'] . 's_desc.png" border="0" width="11" height="9" alt="'. $GLOBALS['strDescending'] . '" title="'. $GLOBALS['strDescending'] . '" id="soimg' . $i . '" />';
  813.             }
  814.             if (preg_match('@(.*)([[:space:]](LIMIT (.*)|PROCEDURE (.*)|FOR UPDATE|LOCK IN SHARE MODE))@i', $unsorted_sql_query, $regs3)) {
  815.                 $sorted_sql_query = $regs3[1] . $sort_order . $regs3[2];
  816.             } else {
  817.                 $sorted_sql_query = $unsorted_sql_query . $sort_order;
  818.             }
  819.             $url_query = PMA_generate_common_url($db, $table)
  820.                        . '&pos=' . $pos
  821.                        . '&session_max_rows=' . $session_max_rows
  822.                        . '&disp_direction=' . $disp_direction
  823.                        . '&repeat_cells=' . $repeat_cells
  824.                        . '&dontlimitchars=' . $dontlimitchars
  825.                        . '&sql_query=' . urlencode($sorted_sql_query);
  826.  
  827.             // 2.1.5 Displays the sorting url
  828.             // added 20004-06-09: Michael Keck <mail@michaelkeck.de>
  829.             //                    enable sord order swapping for image
  830.             $order_onmouse = '';
  831.             if (isset($order_img) && $order_img!='') {
  832.                 if (strstr($order_img,'asc')) {
  833.                     $order_onmouse.= ' onmouseover="if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }"'
  834.                                    .' onmouseout="if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }"';
  835.                 } else if (strstr($order_img,'desc')) {
  836.                     $order_onmouse.= ' onmouseover="if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_asc.png\'; }"'
  837.                                    .' onmouseout="if(document.getElementById(\'soimg' . $i . '\')){ document.getElementById(\'soimg' . $i . '\').src=\'' . $GLOBALS['pmaThemeImage'] . 's_desc.png\'; }"';
  838.                 }
  839.             }
  840.             $order_link_pre  = '<a href="sql.php?' . $url_query . '" ' . (($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css') ? 'style="direction: ltr; writing-mode: tb-rl;"' : '') . ' title="' . $GLOBALS['strSort'] . '"' . $order_onmouse . '>';
  841.             $order_link_post = '</a>';
  842.             $order_link_content = ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake' ? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name));
  843.             $order_link_words = explode(' ', $order_link_content);
  844.             if (isset($order_link_words[1])) {
  845.                 $order_last_word_index = count($order_link_words)-1;
  846.                 $order_last_word = $order_link_words[$order_last_word_index];
  847.                 unset($order_link_words[$order_last_word_index]);
  848.                 $order_link = $order_link_pre . implode(' ', $order_link_words)
  849.                             . ' <div class="nowrap">' . $order_last_word . $order_img . '</div>' . $order_link_post . "\n";
  850.             } else {
  851.                 $order_link = '<div class="nowrap">' . $order_link_pre . $order_link_content . $order_link_post . $order_img . '</div>' . "\n";
  852.             }
  853.  
  854.             if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  855.                 echo "\n";
  856.                 ?>
  857. <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>>
  858.     <?php echo $comments_table_wrap_pre; ?>
  859.     <?php echo $order_link; ?>
  860.     <?php echo $comments_table_wrap_post; ?>
  861. </th>
  862.                 <?php
  863.             }
  864.             $vertical_display['desc'][] = '    <th ' . $column_style . '>' . "\n"
  865.                                         . $comments_table_wrap_pre
  866.                                         . $order_link
  867.                                         . $comments_table_wrap_post
  868.                                         . '    </th>' . "\n";
  869.         } // end if (2.1)
  870.  
  871.         // 2.2 Results can't be sorted
  872.         else {
  873.             if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  874.                 echo "\n";
  875.                 ?>
  876. <th <?php echo $column_style; ?> <?php if ($disp_direction == 'horizontalflipped') echo 'valign="bottom"'; ?>  <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'css' ? 'style="direction: ltr; writing-mode: tb-rl;"' : ''); ?>>
  877.     <?php echo $comments_table_wrap_pre; ?>
  878.     <?php echo ($disp_direction == 'horizontalflipped' && $GLOBALS['cfg']['HeaderFlipType'] == 'fake'? PMA_flipstring(htmlspecialchars($fields_meta[$i]->name), "<br />\n") : htmlspecialchars($fields_meta[$i]->name)) . "\n"; ?>
  879.     <?php echo $comments_table_wrap_post; ?>
  880. </th>
  881.                 <?php
  882.             }
  883.             $vertical_display['desc'][] = '    <th ' . $column_style . '>' . "\n"
  884.                                         . $comments_table_wrap_pre
  885.                                         . '        ' . htmlspecialchars($fields_meta[$i]->name) . "\n"
  886.                                         . $comments_table_wrap_post
  887.                                         . '    </th>';
  888.         } // end else (2.2)
  889.     } // end for
  890.  
  891.     // 3. Displays the full/partial text button (part 2) at the right
  892.     //    column of the result table header if possible and required...
  893.     if ($GLOBALS['cfg']['ModifyDeleteAtRight']
  894.         && ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn')
  895.         && $is_display['text_btn'] == '1') {
  896.         $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
  897.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  898.             echo "\n";
  899.             ?>
  900. <th class="td" <?php echo $colspan; ?> align="center">
  901.     <a href="<?php echo $text_url; ?>">
  902.         <img src="<?php echo $GLOBALS['pmaThemeImage'] . 's_' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png'; ?>" border="0" width="50" height="20" alt="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" title="<?php echo (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']); ?>" /></a>
  903. </th>
  904.             <?php
  905.         } // end horizontal/horizontalflipped mode
  906.         else {
  907.             $vertical_display['textbtn'] = '    <th class="td" ' . $rowspan . ' align="center" valign="middle">' . "\n"
  908.                                          . '        <a href="' . $text_url . '">' . "\n"
  909.                                          . '            <img src="' . $GLOBALS['pmaThemeImage'] . 's_' . (($dontlimitchars) ? 'partialtext' : 'fulltext') . '.png" border="0" width="50" height="20" alt="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" title="' . (($dontlimitchars) ? $GLOBALS['strPartialText'] : $GLOBALS['strFullText']) . '" /></a>' . "\n"
  910.                                          . '    </th>' . "\n";
  911.         } // end vertical mode
  912.     }
  913.  
  914.     //     ... else if no button, displays empty cols if required
  915.     // (unless coming from Browse mode print view)
  916.     else if ($GLOBALS['cfg']['ModifyDeleteAtRight']
  917.              && ($is_display['edit_lnk'] == 'nn' && $is_display['del_lnk'] == 'nn')
  918.              && (!$GLOBALS['is_header_sent'])) {
  919.         $vertical_display['emptyafter'] = ($is_display['edit_lnk'] != 'nn' && $is_display['del_lnk'] != 'nn') ? 3 : 1;
  920.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  921.             echo "\n";
  922.             ?>
  923. <td<?php echo $colspan; ?>></td>
  924.             <?php
  925.         } // end horizontal/horizontalflipped mode
  926.         else {
  927.             $vertical_display['textbtn'] = '    <td' . $rowspan . '></td>' . "\n";
  928.         } // end vertical mode
  929.     }
  930.  
  931.     if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  932.         echo "\n";
  933.         ?>
  934. </tr>
  935.         <?php
  936.     }
  937.     echo "\n";
  938.  
  939.     return TRUE;
  940. } // end of the 'PMA_displayTableHeaders()' function
  941.  
  942.  
  943.  
  944. /**
  945.  * Displays the body of the results table
  946.  *
  947.  * @param   integer  the link id associated to the query which results have
  948.  *                   to be displayed
  949.  * @param   array    which elements to display
  950.  * @param   array    the list of relations
  951.  * @param   array    the analyzed query
  952.  *
  953.  * @return  boolean  always true
  954.  *
  955.  * @global  string   the current language
  956.  * @global  string   the current charset for MySQL
  957.  * @global  integer  the server to use (refers to the number in the
  958.  *                   configuration file)
  959.  * @global  string   the database name
  960.  * @global  string   the table name
  961.  * @global  string   the sql query
  962.  * @global  string   the url to go back in case of errors
  963.  * @global  integer  the current position in results
  964.  * @global  integer  the maximum number of rows per page
  965.  * @global  array    the list of fields properties
  966.  * @global  integer  the total number of fields returned by the sql query
  967.  * @global  array    informations used with vertical display mode
  968.  * @global  string   the display mode (horizontal/vertical/horizontalflipped)
  969.  * @global  integer  the number of row to display between two table headers
  970.  * @global  boolean  whether to limit the number of displayed characters of
  971.  *                   text type fields or not
  972.  *
  973.  * @access  private
  974.  *
  975.  * @see     PMA_displayTable()
  976.  */
  977. function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql)
  978. {
  979.     global $lang, $convcharset, $server, $db, $table;
  980.     global $goto;
  981.     global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt;
  982.     global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
  983.     global $dontlimitchars;
  984.     global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin
  985.  
  986.     $url_sql_query          = $sql_query;
  987.  
  988.     // query without conditions to shorten urls when needed, 200 is just
  989.     // guess, it should depend on remaining url length
  990.  
  991.     if (isset($analyzed_sql) && isset($analyzed_sql[0]) &&
  992.         isset($analyzed_sql[0]['querytype']) && $analyzed_sql[0]['querytype'] == 'SELECT' &&
  993.         strlen($sql_query) > 200) {
  994.  
  995.         $url_sql_query = 'SELECT ';
  996.         if (isset($analyzed_sql[0]['queryflags']['distinct'])) {
  997.             $url_sql_query .= ' DISTINCT ';
  998.         }
  999.         $url_sql_query .= $analyzed_sql[0]['select_expr_clause'];
  1000.         if (!empty($analyzed_sql[0]['from_clause'])) {
  1001.             $url_sql_query .= ' FROM ' . $analyzed_sql[0]['from_clause'];
  1002.         }
  1003.     }
  1004.  
  1005.     if (!is_array($map)) {
  1006.         $map = array();
  1007.     }
  1008.     ?>
  1009. <!-- Results table body -->
  1010.     <?php
  1011.     echo "\n";
  1012.  
  1013.     $row_no                         = 0;
  1014.     $vertical_display['edit']       = array();
  1015.     $vertical_display['delete']     = array();
  1016.     $vertical_display['data']       = array();
  1017.     $vertical_display['row_delete'] = array();
  1018.  
  1019.     // Correction uva 19991216 in the while below
  1020.     // Previous code assumed that all tables have keys, specifically that
  1021.     // the phpMyAdmin GUI should support row delete/edit only for such
  1022.     // tables.
  1023.     // Although always using keys is arguably the prescribed way of
  1024.     // defining a relational table, it is not required. This will in
  1025.     // particular be violated by the novice.
  1026.     // We want to encourage phpMyAdmin usage by such novices. So the code
  1027.     // below has been changed to conditionally work as before when the
  1028.     // table being displayed has one or more keys; but to display
  1029.     // delete/edit options correctly for tables without keys.
  1030.  
  1031.     // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row'
  1032.     //        to get the NULL values
  1033.  
  1034.     // rabus: This function needs a little rework.
  1035.     //        Using MYSQL_BOTH just pollutes the memory!
  1036.  
  1037.     // ne0x:  Use function PMA_DBI_fetch_array() due to mysqli
  1038.     //        compatibility. Now this function is wrapped.
  1039.  
  1040.     while ($row = PMA_DBI_fetch_row($dt_result)) {
  1041.         // lem9: "vertical display" mode stuff
  1042.         if (($row_no != 0) && ($repeat_cells != 0) && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
  1043.             echo '<tr>' . "\n";
  1044.  
  1045.             for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) {
  1046.                 echo '    <th class="td"> </th>' . "\n";
  1047.             }
  1048.  
  1049.             foreach ($vertical_display['desc'] AS $key => $val) {
  1050.                 echo $val;
  1051.             }
  1052.  
  1053.             for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) {
  1054.                 echo '    <th class="td"> </th>' . "\n";
  1055.             }
  1056.  
  1057.             echo '</tr>' . "\n";
  1058.         } // end if
  1059.  
  1060.         if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
  1061.             $bgcolor = '#ffffff';
  1062.         } else {
  1063.             $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
  1064.         }
  1065.  
  1066.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  1067.             // loic1: pointer code part
  1068.             $on_mouse     = '';
  1069.             if (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1')) {
  1070.                 if ($GLOBALS['cfg']['BrowsePointerEnable'] == TRUE) {
  1071.                     $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
  1072.                               . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
  1073.                 } else {
  1074.                     $on_mouse = '';
  1075.                 }
  1076.                 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == TRUE) {
  1077.                     $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
  1078.                 }
  1079.             } // end if
  1080.             ?>
  1081. <tr<?php echo $on_mouse; ?>>
  1082.             <?php
  1083.             echo "\n";
  1084.         }
  1085.  
  1086.         // 1. Prepares the row (gets primary keys to use)
  1087.         if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') {
  1088.             // 1.1 Results from a "SELECT" statement -> builds the
  1089.             //     "primary" key to use in links
  1090.             if ($is_display['edit_lnk'] == 'ur' /* || $is_display['edit_lnk'] == 'dr' */) {
  1091.                 $uva_condition     = urlencode(PMA_getUvaCondition($dt_result, $fields_cnt, $fields_meta, $row));
  1092.             } // end if (1.1)
  1093.  
  1094.             // 1.2 Defines the urls for the modify/delete link(s)
  1095.             $url_query  = PMA_generate_common_url($db, $table)
  1096.                         . '&pos=' . $pos
  1097.                         . '&session_max_rows=' . $session_max_rows
  1098.                         . '&disp_direction=' . $disp_direction
  1099.                         . '&repeat_cells=' . $repeat_cells
  1100.                         . '&dontlimitchars=' . $dontlimitchars;
  1101.  
  1102.             // We need to copy the value or else the == 'both' check will always return true
  1103.             $propicon = (string)$GLOBALS['cfg']['PropertiesIconic'];
  1104.  
  1105.             if ($propicon == 'both') {
  1106.                 $iconic_spacer = '<div class="nowrap">';
  1107.             } else {
  1108.                 $iconic_spacer = '';
  1109.             }
  1110.  
  1111.             // 1.2.1 Modify link(s)
  1112.             if ($is_display['edit_lnk'] == 'ur') { // update row case
  1113. //                    $lnk_goto = 'sql.php'
  1114. //                             . '?' . str_replace('&', '&', $url_query)
  1115. //                              . '&sql_query=' . urlencode($sql_query)
  1116. //                              . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
  1117. // to reduce the length of the URL, because of some browsers limitations:
  1118.                 $lnk_goto = 'sql.php';
  1119.  
  1120.                 $edit_url = 'tbl_change.php'
  1121.                           . '?' . $url_query
  1122.                           . '&primary_key=' . $uva_condition
  1123.                           . '&sql_query=' . urlencode($url_sql_query)
  1124.                           . '&goto=' . urlencode($lnk_goto);
  1125.                 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
  1126.                     $edit_str = $GLOBALS['strEdit'];
  1127.                 } else {
  1128.                     $edit_str = $iconic_spacer . '<img width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" border="0" />';
  1129.                     if ($propicon == 'both') {
  1130.                         $edit_str .= ' ' . $GLOBALS['strEdit'] . '</div>';
  1131.                     }
  1132.                 }
  1133.             } // end if (1.2.1)
  1134.  
  1135.             if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db'] && isset($row[1]) && isset($row[0])) {
  1136.                 $bookmark_go = '<a href="read_dump.php?'
  1137.                                 . PMA_generate_common_url($row[1], '')
  1138.                                 . '&id_bookmark=' . $row[0]
  1139.                                 . '&action_bookmark=0'
  1140.                                 . '&action_bookmark_all=1'
  1141.                                 . '&SQL=' . $GLOBALS['strExecuteBookmarked']
  1142.                                 .' " title="' . $GLOBALS['strExecuteBookmarked'] . '">';
  1143.  
  1144.                 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
  1145.                     $bookmark_go .= $GLOBALS['strExecuteBookmarked'];
  1146.                 } else {
  1147.                     $bookmark_go .= $iconic_spacer . '<img width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" border="0" />';
  1148.                     if ($propicon == 'both') {
  1149.                         $bookmark_go .= ' ' . $GLOBALS['strExecuteBookmarked'] . '</div>';
  1150.                     }
  1151.                 }
  1152.  
  1153.                 $bookmark_go .= '</a>';
  1154.             } else {
  1155.                 $bookmark_go = '';
  1156.             }
  1157.  
  1158.             // 1.2.2 Delete/Kill link(s)
  1159.             if ($is_display['del_lnk'] == 'dr') { // delete row case
  1160.                 $lnk_goto = 'sql.php'
  1161.                           . '?' . str_replace('&', '&', $url_query)
  1162.                           . '&sql_query=' . urlencode($url_sql_query)
  1163.                           . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
  1164.                           . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto);
  1165.                 $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . '+LIMIT+1';
  1166.                 $del_url  = 'sql.php'
  1167.                           . '?' . $url_query
  1168.                           . '&sql_query=' . $del_query
  1169.                           . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted']))
  1170.                           . '&goto=' . urlencode($lnk_goto);
  1171.                 $js_conf  = 'DELETE FROM ' . PMA_jsFormat($table)
  1172.                           . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE))
  1173.                           . ' LIMIT 1';
  1174.                 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
  1175.                     $del_str = $GLOBALS['strDelete'];
  1176.                 } else {
  1177.                     $del_str = $iconic_spacer . '<img width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" border="0" />';
  1178.                     if ($propicon == 'both') {
  1179.                         $del_str .= ' ' . $GLOBALS['strDelete'] . '</div>';
  1180.                     }
  1181.                 }
  1182.             } else if ($is_display['del_lnk'] == 'kp') { // kill process case
  1183.                 $lnk_goto = 'sql.php'
  1184.                           . '?' . str_replace('&', '&', $url_query)
  1185.                           . '&sql_query=' . urlencode($url_sql_query)
  1186.                           . '&goto=main.php';
  1187.                 $del_url  = 'sql.php?'
  1188.                           . PMA_generate_common_url('mysql')
  1189.                           . '&sql_query=' . urlencode('KILL ' . $row[0])
  1190.                           . '&goto=' . urlencode($lnk_goto);
  1191.                 $del_query = urlencode('KILL ' . $row[0]);
  1192.                 $js_conf  = 'KILL ' . $row[0];
  1193.                 if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) {
  1194.                     $del_str = $GLOBALS['strKill'];
  1195.                 } else {
  1196.                     $del_str = $iconic_spacer . '<img width="16" height="16" src="' . $GLOBALS['pmaThemeImage'] . 'b_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" border="0" />';
  1197.                     if ($propicon == 'both') {
  1198.                         $del_str .= ' ' . $GLOBALS['strKill'] . '</div>';
  1199.                     }
  1200.                 }
  1201.             } // end if (1.2.2)
  1202.  
  1203.             // 1.3 Displays the links at left if required
  1204.             if ($GLOBALS['cfg']['ModifyDeleteAtLeft']
  1205.                 && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
  1206.                 $doWriteModifyAt = 'left';
  1207.                 require('./libraries/display_tbl_links.lib.php');
  1208.             } // end if (1.3)
  1209.             echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
  1210.         } // end if (1)
  1211.  
  1212.         // 2. Displays the rows' values
  1213.         for ($i = 0; $i < $fields_cnt; ++$i) {
  1214.             $meta    = $fields_meta[$i];
  1215.             // loic1: To fix bug #474943 under php4, the row pointer will
  1216.             //        depend on whether the "is_null" php4 function is
  1217.             //        available or not
  1218.             $pointer = (function_exists('is_null') ? $i : $meta->name);
  1219.             // garvin: See if this column should get highlight because it's used in the
  1220.             //  where-query.
  1221.             if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) {
  1222.                 $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"';
  1223.             } else {
  1224.                 $column_style = '';
  1225.             }
  1226.  
  1227.             if ($disp_direction == 'vertical' && (!isset($GLOBALS['printview']) || ($GLOBALS['printview'] != '1'))) {
  1228.                 if ($GLOBALS['cfg']['BrowsePointerColor'] == TRUE) {
  1229.                     $column_style .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
  1230.                               . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
  1231.                 }
  1232.                 if ($GLOBALS['cfg']['BrowseMarkerEnable'] == TRUE) {
  1233.                     $column_style .= ' onmousedown="setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\'); setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');"';
  1234.                 } else {
  1235.                     $column_style .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
  1236.                 }
  1237.             } else {
  1238.                 $column_style .= ' onmousedown="setCheckboxColumn(\'id_rows_to_delete' . $row_no . '\');" ';
  1239.             }// end if
  1240.  
  1241.             // garvin: Wrap MIME-transformations. [MIME]
  1242.             $default_function = 'default_function'; // default_function
  1243.             $transform_function = $default_function;
  1244.             $transform_options = array();
  1245.  
  1246.             if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) {
  1247.  
  1248.                 if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) {
  1249.                     $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']);
  1250.  
  1251.                     if (file_exists('./libraries/transformations/' . $include_file)) {
  1252.                         $transformfunction_name = preg_replace('@(\.inc\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']);
  1253.  
  1254.                         require_once('./libraries/transformations/' . $include_file);
  1255.  
  1256.                         if (function_exists('PMA_transformation_' . $transformfunction_name)) {
  1257.                             $transform_function = 'PMA_transformation_' . $transformfunction_name;
  1258.                             $transform_options  = PMA_transformation_getOptions((isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''));
  1259.                             $meta->mimetype     = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']);
  1260.                         }
  1261.                     } // end if file_exists
  1262.                 } // end if transformation is set
  1263.             } // end if mime/transformation works.
  1264.  
  1265.             $transform_options['wrapper_link'] = '?'
  1266.                                                 . (isset($url_query) ? $url_query : '')
  1267.                                                 . '&primary_key=' . (isset($uva_condition) ? $uva_condition : '')
  1268.                                                 . '&sql_query=' . (isset($sql_query) ? urlencode($url_sql_query) : '')
  1269.                                                 . '&goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '')
  1270.                                                 . '&transform_key=' . urlencode($meta->name);
  1271.  
  1272.  
  1273.             // n u m e r i c
  1274.             if ($meta->numeric == 1) {
  1275.  
  1276.  
  1277.             // lem9: if two fields have the same name (this is possible
  1278.             //       with self-join queries, for example), using $meta->name
  1279.             //       will show both fields NULL even if only one is NULL,
  1280.             //       so use the $pointer
  1281.             //      (works only if function_exists('is_null')
  1282.             // PS:   why not always work with the number ($i), since
  1283.             //       the default second parameter of
  1284.             //       mysql_fetch_array() is MYSQL_BOTH, so we always get
  1285.             //       associative and numeric indices?
  1286.  
  1287.                 //if (!isset($row[$meta->name])
  1288.                 if (!isset($row[$i]) || is_null($row[$i])) {
  1289.                     $vertical_display['data'][$row_no][$i]     = '    <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
  1290.                 } else if ($row[$i] != '') {
  1291.                     $vertical_display['data'][$row_no][$i]     = '    <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '" class="nowrap">';
  1292.  
  1293.                     if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
  1294.                         foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
  1295.                             $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
  1296.                             if (!empty($alias)) {
  1297.                                 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
  1298.                                 if ($alias == $meta->name) {
  1299.                                     $meta->name = $true_column;
  1300.                                 } // end if
  1301.                             } // end if
  1302.                         } // end while
  1303.                     }
  1304.  
  1305.                     if (isset($map[$meta->name])) {
  1306.                         // Field to display from the foreign table?
  1307.                         if (!empty($map[$meta->name][2])) {
  1308.                             $dispsql     = 'SELECT ' . PMA_backquote($map[$meta->name][2])
  1309.                                          . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
  1310.                                          . ' WHERE ' . PMA_backquote($map[$meta->name][1])
  1311.                                          . ' = ' . $row[$i];
  1312.                             $dispresult  = PMA_DBI_try_query($dispsql, NULL, PMA_DBI_QUERY_STORE);
  1313.                             if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
  1314.                                 list($dispval) = PMA_DBI_fetch_row($dispresult, 0);
  1315.                             }
  1316.                             else {
  1317.                                 $dispval = $GLOBALS['strLinkNotFound'];
  1318.                             }
  1319.                             @PMA_DBI_free_result($dispresult);
  1320.                         }
  1321.                         else {
  1322.                             $dispval     = '';
  1323.                         } // end if... else...
  1324.  
  1325.                         if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') {
  1326.                             $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . ' <code>[->' . $dispval . ']</code>';
  1327.                         } else {
  1328.                             $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
  1329.  
  1330.                             $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
  1331.                                                                    .  PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
  1332.                                                                    .  '&pos=0&session_max_rows=' . $session_max_rows . '&dontlimitchars=' . $dontlimitchars
  1333.                                                                    .  '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$i]) . '"' . $title . '>'
  1334.                                                                    .  ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta)) . '</a>';
  1335.                         }
  1336.                     } else {
  1337.                         $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$i], $transform_options, $meta) : $transform_function($row[$i], array(), $meta));
  1338.                     }
  1339.                     $vertical_display['data'][$row_no][$i]     .= '</td>' . "\n";
  1340.                 } else {
  1341.                     $vertical_display['data'][$row_no][$i]     = '    <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '" class="nowrap"> </td>' . "\n";
  1342.                 }
  1343.  
  1344.             //  b l o b
  1345.  
  1346.             } else if ($GLOBALS['cfg']['ShowBlob'] == FALSE && stristr($meta->type, 'BLOB')) {
  1347.                 // loic1 : PMA_mysql_fetch_fields returns BLOB in place of
  1348.                 // TEXT fields type, however TEXT fields must be displayed
  1349.                 // even if $cfg['ShowBlob'] is false -> get the true type
  1350.                 // of the fields.
  1351.                 $field_flags = PMA_DBI_field_flags($dt_result, $i);
  1352.                 if (stristr($field_flags, 'BINARY')) {
  1353.                     $blobtext = '[BLOB';
  1354.                     if (!isset($row[$i]) || is_null($row[$i])) {
  1355.                         $blobtext .= ' - NULL';
  1356.                     } elseif (isset($row[$i])) {
  1357.                         $blob_size = PMA_formatByteDown(strlen($row[$i]), 3, 1);
  1358.                         $blobtext .= ' - '. $blob_size [0] . ' ' . $blob_size[1];
  1359.                         unset($blob_size);
  1360.                     }
  1361.  
  1362.                     $blobtext .= ']';
  1363.                     $blobtext = ($default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta));
  1364.  
  1365.                     $vertical_display['data'][$row_no][$i]      = '    <td align="center" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>';
  1366.                 } else {
  1367.                     if (!isset($row[$i]) || is_null($row[$i])) {
  1368.                         $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
  1369.                     } else if ($row[$i] != '') {
  1370.                         // garvin: if a transform function for blob is set, none of these replacements will be made
  1371.                         if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
  1372.                             $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
  1373.                         }
  1374.                         // loic1: displays all space characters, 4 space
  1375.                         // characters for tabulations and <cr>/<lf>
  1376.                         $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
  1377.  
  1378.                         $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">' . $row[$i] . '</td>' . "\n";
  1379.                     } else {
  1380.                         $vertical_display['data'][$row_no][$i] = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"> </td>' . "\n";
  1381.                     }
  1382.                 }
  1383.             } else {
  1384.                 if (!isset($row[$i]) || is_null($row[$i])) {
  1385.                     $vertical_display['data'][$row_no][$i]     = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n";
  1386.                 } else if ($row[$i] != '') {
  1387.                     // loic1: support blanks in the key
  1388.                     $relation_id = $row[$i];
  1389.  
  1390.                     // nijel: Cut all fields to $cfg['LimitChars']
  1391.                     if (PMA_strlen($row[$i]) > $GLOBALS['cfg']['LimitChars'] && ($dontlimitchars != 1)) {
  1392.                         $row[$i] = PMA_substr($row[$i], 0, $GLOBALS['cfg']['LimitChars']) . '...';
  1393.                     }
  1394.  
  1395.                     // loic1: displays special characters from binaries
  1396.                     $field_flags = PMA_DBI_field_flags($dt_result, $i);
  1397.                     if (stristr($field_flags, 'BINARY')) {
  1398.                         $row[$i]     = str_replace("\x00", '\0', $row[$i]);
  1399.                         $row[$i]     = str_replace("\x08", '\b', $row[$i]);
  1400.                         $row[$i]     = str_replace("\x0a", '\n', $row[$i]);
  1401.                         $row[$i]     = str_replace("\x0d", '\r', $row[$i]);
  1402.                         $row[$i]     = str_replace("\x1a", '\Z', $row[$i]);
  1403.                         $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
  1404.                     }
  1405.                     // loic1: displays all space characters, 4 space
  1406.                     // characters for tabulations and <cr>/<lf>
  1407.                     else {
  1408.                         $row[$i]     = ($default_function != $transform_function ? $transform_function($row[$i], $transform_options, $meta) : $default_function($row[$i], array(), $meta));
  1409.                     }
  1410.  
  1411.                     // garvin: transform functions may enable nowrapping:
  1412.                     $function_nowrap = $transform_function . '_nowrap';
  1413.                     $bool_nowrap = (($default_function != $transform_function && function_exists($function_nowrap)) ? $function_nowrap($transform_options) : false);
  1414.  
  1415.                     // loic1: do not wrap if date field type
  1416.                     $nowrap = ((preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap) ? ' nowrap="nowrap"' : '');
  1417.                     $vertical_display['data'][$row_no][$i]     = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>';
  1418.  
  1419.                     if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) {
  1420.                         foreach ($analyzed_sql[0]['select_expr'] AS $select_expr_position => $select_expr) {
  1421.                             $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias'];
  1422.                             if (!empty($alias)) {
  1423.                                 $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column'];
  1424.                                 if ($alias == $meta->name) {
  1425.                                     $meta->name = $true_column;
  1426.                                 } // end if
  1427.                             } // end if
  1428.                         } // end while
  1429.                     }
  1430.  
  1431.                     if (isset($map[$meta->name])) {
  1432.                         // Field to display from the foreign table?
  1433.                         if (!empty($map[$meta->name][2])) {
  1434.                             $dispsql     = 'SELECT ' . PMA_backquote($map[$meta->name][2])
  1435.                                          . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0])
  1436.                                          . ' WHERE ' . PMA_backquote($map[$meta->name][1])
  1437.                                          . ' = \'' . PMA_sqlAddslashes($row[$i]) . '\'';
  1438.                             $dispresult  = PMA_DBI_try_query($dispsql, NULL, PMA_DBI_QUERY_STORE);
  1439.                             if ($dispresult && PMA_DBI_num_rows($dispresult) > 0) {
  1440.                                 list($dispval) = PMA_DBI_fetch_row($dispresult);
  1441.                                 @PMA_DBI_free_result($dispresult);
  1442.                             }
  1443.                             else {
  1444.                                 $dispval = $GLOBALS['strLinkNotFound'];
  1445.                             }
  1446.                         }
  1447.                         else {
  1448.                             $dispval = '';
  1449.                         }
  1450.                         $title = (!empty($dispval))? ' title="' . htmlspecialchars($dispval) . '"' : '';
  1451.  
  1452.                         $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?'
  1453.                                                                .  PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0])
  1454.                                                                .  '&pos=0&session_max_rows=' . $session_max_rows . '&dontlimitchars=' . $dontlimitchars
  1455.                                                                .  '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>'
  1456.                                                                .  $row[$i] . '</a>';
  1457.                     } else {
  1458.                         $vertical_display['data'][$row_no][$i] .= $row[$i];
  1459.                     }
  1460.                     $vertical_display['data'][$row_no][$i]     .= '</td>' . "\n";
  1461.                 } else {
  1462.                     $vertical_display['data'][$row_no][$i]     = '    <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"> </td>' . "\n";
  1463.                 }
  1464.             }
  1465.  
  1466.             // lem9: output stored cell
  1467.             if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  1468.                 echo $vertical_display['data'][$row_no][$i];
  1469.             }
  1470.  
  1471.             if (isset($vertical_display['rowdata'][$i][$row_no])) {
  1472.                 $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i];
  1473.             } else {
  1474.                 $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i];
  1475.             }
  1476.         } // end for (2)
  1477.  
  1478.         // 3. Displays the modify/delete links on the right if required
  1479.         if ($GLOBALS['cfg']['ModifyDeleteAtRight']
  1480.             && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) {
  1481.                 $doWriteModifyAt = 'right';
  1482.                 require('./libraries/display_tbl_links.lib.php');
  1483.         } // end if (3)
  1484.  
  1485.         if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') {
  1486.             echo "\n";
  1487.             ?>
  1488. </tr>
  1489.             <?php
  1490.         } // end if
  1491.  
  1492.         // 4. Gather links of del_urls and edit_urls in an array for later
  1493.         //    output
  1494.         if (!isset($vertical_display['edit'][$row_no])) {
  1495.             $vertical_display['edit'][$row_no]       = '';
  1496.             $vertical_display['delete'][$row_no]     = '';
  1497.             $vertical_display['row_delete'][$row_no] = '';
  1498.         }
  1499.  
  1500.         $column_style_vertical = '';
  1501.         if ($GLOBALS['cfg']['BrowsePointerEnable'] == TRUE) {
  1502.             $column_style_vertical .= ' onmouseover="setVerticalPointer(this, ' . $row_no . ', \'over\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'
  1503.                          . ' onmouseout="setVerticalPointer(this, ' . $row_no . ', \'out\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"';
  1504.         }
  1505.         $column_marker_vertical = '';
  1506.         if ($GLOBALS['cfg']['BrowseMarkerEnable'] == TRUE) {
  1507.             $column_marker_vertical .= 'setVerticalPointer(this, ' . $row_no . ', \'click\', \'' . $GLOBALS['cfg']['BgcolorOne'] . '\', \'' . $GLOBALS['cfg']['BgcolorTwo'] . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');';
  1508.         }
  1509.  
  1510.         if (!empty($del_url) && $is_display['del_lnk'] != 'kp') {
  1511.             $vertical_display['row_delete'][$row_no] .= '    <td align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '"' . $column_style_vertical . '>' . "\n"
  1512.                                                      .  '        <input type="checkbox" id="id_rows_to_delete' . $row_no . '[%_PMA_CHECKBOX_DIR_%]" name="rows_to_delete[' . $uva_condition . ']"'
  1513.                                                      .  ' onclick="' . $column_marker_vertical . 'copyCheckboxesRange(\'rowsDeleteForm\', \'id_rows_to_delete' . $row_no . '\',\'[%_PMA_CHECKBOX_DIR_%]\');"'
  1514.                                                      .  ' value="' . $del_query . '" ' . (isset($GLOBALS['checkall']) ? 'checked="checked"' : '') . ' />' . "\n"
  1515.                                                      .  '    </td>' . "\n";
  1516.         } else {
  1517.             unset($vertical_display['row_delete'][$row_no]);
  1518.         }
  1519.  
  1520.         if (isset($edit_url)) {
  1521.             $vertical_display['edit'][$row_no]   .= '    <td align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '"' . $column_style_vertical . '>' . "\n"
  1522.                                                  . PMA_linkOrButton($edit_url, $edit_str, '', FALSE)
  1523.                                                  . $bookmark_go
  1524.                                                  .  '    </td>' . "\n";
  1525.         } else {
  1526.             unset($vertical_display['edit'][$row_no]);
  1527.         }
  1528.  
  1529.         if (isset($del_url)) {
  1530.             $vertical_display['delete'][$row_no] .= '    <td align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '"' . $column_style_vertical . '>' . "\n"
  1531.                                                  . PMA_linkOrButton($del_url, $del_str, (isset($js_conf) ? $js_conf : ''), FALSE)
  1532.                                                  .  '    </td>' . "\n";
  1533.         } else {
  1534.             unset($vertical_display['delete'][$row_no]);
  1535.         }
  1536.  
  1537.         echo (($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') ? "\n" : '');
  1538.         $row_no++;
  1539.     } // end while
  1540.  
  1541.     if (isset($url_query)) {
  1542.         $GLOBALS['url_query'] = $url_query;
  1543.     }
  1544.  
  1545.     return TRUE;
  1546. } // end of the 'PMA_displayTableBody()' function
  1547.  
  1548.  
  1549. /**
  1550.  * Do display the result table with the vertical direction mode.
  1551.  * Credits for this feature goes to Garvin Hicking <hicking@faktor-e.de>.
  1552.  *
  1553.  * @return  boolean  always true
  1554.  *
  1555.  * @global  array    the information to display
  1556.  * @global  integer  the number of row to display between two table headers
  1557.  *
  1558.  * @access  private
  1559.  *
  1560.  * @see     PMA_displayTable()
  1561.  */
  1562. function PMA_displayVerticalTable()
  1563. {
  1564.     global $vertical_display, $repeat_cells;
  1565.  
  1566.     // Displays "multi row delete" link at top if required
  1567.     if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
  1568.         echo '<tr>' . "\n";
  1569.         echo $vertical_display['textbtn'];
  1570.         $foo_counter = 0;
  1571.         foreach ($vertical_display['row_delete'] AS $key => $val) {
  1572.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1573.                 echo '<th class="td"> </th>' . "\n";
  1574.             }
  1575.  
  1576.             echo str_replace('[%_PMA_CHECKBOX_DIR_%]', '', $val);
  1577.             $foo_counter++;
  1578.         } // end while
  1579.         echo '</tr>' . "\n";
  1580.     } // end if
  1581.  
  1582.     // Displays "edit" link at top if required
  1583.     if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
  1584.         echo '<tr>' . "\n";
  1585.         if (!is_array($vertical_display['row_delete'])) {
  1586.             echo $vertical_display['textbtn'];
  1587.         }
  1588.         $foo_counter = 0;
  1589.         foreach ($vertical_display['edit'] AS $key => $val) {
  1590.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1591.                 echo '    <th class="td"> </th>' . "\n";
  1592.             }
  1593.  
  1594.             echo $val;
  1595.             $foo_counter++;
  1596.         } // end while
  1597.         echo '</tr>' . "\n";
  1598.     } // end if
  1599.  
  1600.     // Displays "delete" link at top if required
  1601.     if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
  1602.         echo '<tr>' . "\n";
  1603.         if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
  1604.             echo $vertical_display['textbtn'];
  1605.         }
  1606.         $foo_counter = 0;
  1607.         foreach ($vertical_display['delete'] AS $key => $val) {
  1608.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1609.                 echo '<th class="td"> </th>' . "\n";
  1610.             }
  1611.  
  1612.             echo $val;
  1613.             $foo_counter++;
  1614.         } // end while
  1615.         echo '</tr>' . "\n";
  1616.     } // end if
  1617.  
  1618.     // Displays data
  1619.     $row_no = 0;
  1620.     foreach ($vertical_display['desc'] AS $key => $val) {
  1621.         $row_no++;
  1622.  
  1623.         if (isset($GLOBALS['printview']) && ($GLOBALS['printview'] == '1')) {
  1624.             $bgcolor = '#ffffff';
  1625.         } else {
  1626.             $bgcolor = ($row_no % 2) ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo'];
  1627.         }
  1628.  
  1629.         echo '<tr>' . "\n";
  1630.         echo $val;
  1631.  
  1632.         $foo_counter = 0;
  1633.         foreach ($vertical_display['rowdata'][$key] AS $subkey => $subval) {
  1634.             if (($foo_counter != 0) && ($repeat_cells != 0) and !($foo_counter % $repeat_cells)) {
  1635.                 echo $val;
  1636.             }
  1637.  
  1638.             echo $subval;
  1639.             $foo_counter++;
  1640.         } // end while
  1641.  
  1642.         echo '</tr>' . "\n";
  1643.     } // end while
  1644.  
  1645.     // Displays "multi row delete" link at bottom if required
  1646.     if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['row_delete']) && (count($vertical_display['row_delete']) > 0 || !empty($vertical_display['textbtn']))) {
  1647.         echo '<tr>' . "\n";
  1648.         echo $vertical_display['textbtn'];
  1649.         $foo_counter = 0;
  1650.         foreach ($vertical_display['row_delete'] AS $key => $val) {
  1651.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1652.                 echo '<th class="td"> </th>' . "\n";
  1653.             }
  1654.  
  1655.             echo str_replace('[%_PMA_CHECKBOX_DIR_%]', 'r', $val);
  1656.             $foo_counter++;
  1657.         } // end while
  1658.         echo '</tr>' . "\n";
  1659.     } // end if
  1660.  
  1661.     // Displays "edit" link at bottom if required
  1662.     if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['edit']) && (count($vertical_display['edit']) > 0 || !empty($vertical_display['textbtn']))) {
  1663.         echo '<tr>' . "\n";
  1664.         if (!is_array($vertical_display['row_delete'])) {
  1665.             echo $vertical_display['textbtn'];
  1666.         }
  1667.         $foo_counter = 0;
  1668.         foreach ($vertical_display['edit'] AS $key => $val) {
  1669.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1670.                 echo '<th class="td"> </th>' . "\n";
  1671.             }
  1672.  
  1673.             echo $val;
  1674.             $foo_counter++;
  1675.         } // end while
  1676.         echo '</tr>' . "\n";
  1677.     } // end if
  1678.  
  1679.     // Displays "delete" link at bottom if required
  1680.     if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && is_array($vertical_display['delete']) && (count($vertical_display['delete']) > 0 || !empty($vertical_display['textbtn']))) {
  1681.         echo '<tr>' . "\n";
  1682.         if (!is_array($vertical_display['edit']) && !is_array($vertical_display['row_delete'])) {
  1683.             echo $vertical_display['textbtn'];
  1684.         }
  1685.         $foo_counter = 0;
  1686.         foreach ($vertical_display['delete'] AS $key => $val) {
  1687.             if (($foo_counter != 0) && ($repeat_cells != 0) && !($foo_counter % $repeat_cells)) {
  1688.                 echo '<th class="td"> </th>' . "\n";
  1689.             }
  1690.  
  1691.             echo $val;
  1692.             $foo_counter++;
  1693.         } // end while
  1694.         echo '</tr>' . "\n";
  1695.     }
  1696.  
  1697.     return TRUE;
  1698. } // end of the 'PMA_displayVerticalTable' function
  1699.  
  1700.  
  1701. /**
  1702.  * Displays a table of results returned by a sql query.
  1703.  * This function is called by the "sql.php" script.
  1704.  *
  1705.  * @param   integer the link id associated to the query which results have
  1706.  *                  to be displayed
  1707.  * @param   array   the display mode
  1708.  * @param   array   the analyzed query
  1709.  *
  1710.  * @global  string   the current language
  1711.  * @global  integer  the server to use (refers to the number in the
  1712.  *                   configuration file)
  1713.  * @global  array    the current server config
  1714.  * @global  string   the database name
  1715.  * @global  string   the table name
  1716.  * @global  string   the url to go back in case of errors
  1717.  * @global  string   the current sql query
  1718.  * @global  integer  the total number of rows returned by the sql query
  1719.  * @global  integer  the total number of rows returned by the sql query
  1720.  *                   without any programmatically appended "LIMIT" clause
  1721.  * @global  integer  the current postion of the first record to be
  1722.  *                   displayed
  1723.  * @global  array    the list of fields properties
  1724.  * @global  integer  the total number of fields returned by the sql query
  1725.  * @global  array    informations used with vertical display mode
  1726.  * @global  string   the display mode (horizontal/vertical/horizontalflipped)
  1727.  * @global  integer  the number of row to display between two table headers
  1728.  * @global  boolean  whether to limit the number of displayed characters of
  1729.  *                   text type fields or not
  1730.  * @global  array    the relation settings
  1731.  *
  1732.  * @access  private
  1733.  *
  1734.  * @see     PMA_showMessage(), PMA_setDisplayMode(),
  1735.  *          PMA_displayTableNavigation(), PMA_displayTableHeaders(),
  1736.  *          PMA_displayTableBody()
  1737.  */
  1738. function PMA_displayTable(&$dt_result, &$the_disp_mode, $analyzed_sql)
  1739. {
  1740.     global $lang, $server, $cfg, $db, $table;
  1741.     global $goto, $text_url;
  1742.     global $sql_query, $num_rows, $unlim_num_rows, $pos, $fields_meta, $fields_cnt;
  1743.     global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns;
  1744.     global $dontlimitchars;
  1745.     global $cfgRelation;
  1746.  
  1747.     // 1. ----- Prepares the work -----
  1748.  
  1749.     // 1.1 Gets the informations about which functionnalities should be
  1750.     //     displayed
  1751.     $total      = '';
  1752.     $is_display = PMA_setDisplayMode($the_disp_mode, $total);
  1753.     if ($total == '') {
  1754.         unset($total);
  1755.     }
  1756.  
  1757.     // 1.2 Defines offsets for the next and previous pages
  1758.     if ($is_display['nav_bar'] == '1') {
  1759.         if (!isset($pos)) {
  1760.             $pos          = 0;
  1761.         }
  1762.         if ($GLOBALS['session_max_rows'] == 'all') {
  1763.             $pos_next     = 0;
  1764.             $pos_prev     = 0;
  1765.         } else {
  1766.             $pos_next     = $pos + $GLOBALS['cfg']['MaxRows'];
  1767.             $pos_prev     = $pos - $GLOBALS['cfg']['MaxRows'];
  1768.             if ($pos_prev < 0) {
  1769.                 $pos_prev = 0;
  1770.             }
  1771.         }
  1772.     } // end if
  1773.  
  1774.     // 1.3 Urlencodes the query to use in input form fields
  1775.     $encoded_sql_query = urlencode($sql_query);
  1776.  
  1777.     // 2. ----- Displays the top of the page -----
  1778.  
  1779.     // 2.1 Displays a messages with position informations
  1780.     if ($is_display['nav_bar'] == '1' && isset($pos_next)) {
  1781.         if (isset($unlim_num_rows) && $unlim_num_rows != $total) {
  1782.             $selectstring = ', ' . $unlim_num_rows . ' ' . $GLOBALS['strSelectNumRows'];
  1783.         } else {
  1784.             $selectstring = '';
  1785.         }
  1786.         $last_shown_rec = ($GLOBALS['session_max_rows'] == 'all' || $pos_next > $total)
  1787.                         ? $total - 1
  1788.                         : $pos_next - 1;
  1789.         PMA_showMessage($GLOBALS['strShowingRecords'] . " $pos - $last_shown_rec ($total " . $GLOBALS['strTotal'] . $selectstring . ', ' . sprintf($GLOBALS['strQueryTime'], $GLOBALS['querytime']) . ')');
  1790.     } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
  1791.         PMA_showMessage($GLOBALS['strSQLQuery']);
  1792.     }
  1793.  
  1794.     // 2.3 Displays the navigation bars
  1795.     if (!isset($table) || strlen(trim($table)) == 0) {
  1796.         $table = $fields_meta[0]->table;
  1797.     }
  1798.     if ($is_display['nav_bar'] == '1') {
  1799.         PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
  1800.         echo "\n";
  1801.     } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
  1802.         echo "\n" . '<br /><br />' . "\n";
  1803.     }
  1804.  
  1805.     // 2b ----- Get field references from Database -----
  1806.     // (see the 'relation' config variable)
  1807.     // loic1, 2002-03-02: extended to php3
  1808.  
  1809.     // init map
  1810.     $map = array();
  1811.  
  1812.     // find tables
  1813.  
  1814.     $target=array();
  1815.     if (isset($analyzed_sql[0]['table_ref']) && is_array($analyzed_sql[0]['table_ref'])) {
  1816.         foreach ($analyzed_sql[0]['table_ref'] AS $table_ref_position => $table_ref) {
  1817.            $target[] = $analyzed_sql[0]['table_ref'][$table_ref_position]['table_true_name'];
  1818.         }
  1819.     }
  1820.     $tabs    = '(\'' . join('\',\'', $target) . '\')';
  1821.  
  1822.     if ($cfgRelation['displaywork']) {
  1823.         if (empty($table)) {
  1824.             $exist_rel = FALSE;
  1825.         } else {
  1826.             $exist_rel = PMA_getForeigners($db, $table, '', 'both');
  1827.             if ($exist_rel) {
  1828.                 foreach ($exist_rel AS $master_field => $rel) {
  1829.                     $display_field = PMA_getDisplayField($rel['foreign_db'],$rel['foreign_table']);
  1830.                     $map[$master_field] = array($rel['foreign_table'],
  1831.                                           $rel['foreign_field'],
  1832.                                           $display_field,
  1833.                                           $rel['foreign_db']);
  1834.                 } // end while
  1835.             } // end if
  1836.         } // end if
  1837.     } // end if
  1838.     // end 2b
  1839.  
  1840.     // 3. ----- Displays the results table -----
  1841.     PMA_displayTableHeaders($is_display, $fields_meta, $fields_cnt, $analyzed_sql);
  1842.     $url_query='';
  1843.     PMA_displayTableBody($dt_result, $is_display, $map, $analyzed_sql);
  1844.     // vertical output case
  1845.     if ($disp_direction == 'vertical') {
  1846.         PMA_displayVerticalTable();
  1847.     } // end if
  1848.     unset($vertical_display);
  1849.     ?>
  1850. </table>
  1851.     <?php
  1852.  
  1853.     echo "\n";
  1854.  
  1855.     // 4. ----- Displays the link for multi-fields delete
  1856.  
  1857.     if ($is_display['del_lnk'] == 'dr' && $is_display['del_lnk'] != 'kp') {
  1858.  
  1859.         $delete_text = $is_display['del_lnk'] == 'dr' ? $GLOBALS['strDelete'] : $GLOBALS['strKill'];
  1860.         $propicon = (string)$GLOBALS['cfg']['PropertiesIconic'];
  1861. ?>
  1862.           <img src="<?php echo $GLOBALS['pmaThemeImage'] . 'arrow_' . $GLOBALS['text_dir'] . '.png'; ?>" border="0" width="38" height="22" alt="<?php echo $GLOBALS['strWithChecked']; ?>" />
  1863.         <a href="<?php echo $text_url . '&checkall=1'; ?>" onclick="setCheckboxesRange('rowsDeleteForm', true, 'id_rows_to_delete', 0, '<?php echo $num_rows; ?>'); return false;">
  1864.             <?php echo $GLOBALS['strCheckAll']; ?></a>
  1865.          / 
  1866.         <a href="<?php echo $text_url; ?>" onclick="setCheckboxesRange('rowsDeleteForm', false, 'id_rows_to_delete', 0, '<?php echo $num_rows; ?>'); return false;">
  1867.             <?php echo $GLOBALS['strUncheckAll']; ?></a>
  1868. <?php
  1869.           echo '  <i>' . $GLOBALS['strWithChecked'] . '</i>'. "\n";
  1870.  
  1871.         if ($cfg['PropertiesIconic']) {
  1872.             PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_change', $GLOBALS['strChange'], 'b_edit.png');
  1873.             PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_delete', $delete_text, 'b_drop.png');
  1874.             if ($analyzed_sql[0]['querytype'] == 'SELECT') {
  1875.                 PMA_buttonOrImage('submit_mult', 'mult_submit', 'submit_mult_export', $GLOBALS['strExport'], 'b_tblexport.png');
  1876.             }
  1877.             echo "\n";
  1878.         } else {
  1879.             echo '                    <input type="submit" name="submit_mult" value="' . htmlspecialchars($GLOBALS['strEdit']) . '" title="' . $GLOBALS['strEdit'] . '" />' . "\n";
  1880.             echo ' <input type="submit" name="submit_mult" value="' . htmlspecialchars($delete_text) . '" title="' . $delete_text . '" />' . "\n";
  1881.             if ($analyzed_sql[0]['querytype'] == 'SELECT') {
  1882.                 echo ' <input type="submit" name="submit_mult" value="' . htmlspecialchars($GLOBALS['strExport']) . '" title="' . $GLOBALS['strExport'] . '" />' . "\n";
  1883.             }
  1884.         }
  1885.         echo '<input type="hidden" name="sql_query" value="' . htmlspecialchars($sql_query) . '" />' . "\n";
  1886.         echo '<input type="hidden" name="pos" value="' . $pos . '" />' . "\n";
  1887.         echo '<input type="hidden" name="url_query" value="' . $GLOBALS['url_query'] . '" />' . "\n";
  1888.         echo '<br />' . "\n";
  1889.         echo '</form>' . "\n";
  1890.     }
  1891.  
  1892.     // 5. ----- Displays the navigation bar at the bottom if required -----
  1893.  
  1894.     if ($is_display['nav_bar'] == '1') {
  1895.         echo '<br />' . "\n";
  1896.         PMA_displayTableNavigation($pos_next, $pos_prev, $encoded_sql_query);
  1897.     } else if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') {
  1898.         echo "\n" . '<br /><br />' . "\n";
  1899.     }
  1900. } // end of the 'PMA_displayTable()' function
  1901.  
  1902. function default_function($buffer) {
  1903.     $buffer = htmlspecialchars($buffer);
  1904.     $buffer = str_replace("\011", '    ', str_replace('  ', '  ', $buffer));
  1905.     $buffer = preg_replace("@((\015\012)|(\015)|(\012))@", '<br />', $buffer);
  1906.  
  1907.     return $buffer;
  1908. }
  1909. ?>
  1910.